package com.wctj.api.business.common.component;

import com.wctj.api.business.common.config.AsyncConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 异步执行器
 */
@Component
@ConditionalOnBean(AsyncConfig.class)
@Slf4j
public class AsyncExecuteService {

    /**
     * 线程池执行器
     */
    @Resource
    private ThreadPoolTaskExecutor zgzgTaskExecutor;


    /**
     * 异步执行方法
     *
     * @param task 需要执行的方法
     */
    public void execute(Runnable task) {
        zgzgTaskExecutor.execute(task);
    }

}
